package top.reminis.conf;

import lombok.Data;
import java.util.List;
import java.util.Map;

/**
 * 作业配置类
 * 包含通用Flink任务的所有配置信息
 * 
 * @author zwf
 * @create 2025-09-24
 */
@Data
public class JobConfig {
    
    // 作业基本信息
    private String jobName;
    private String description;
    private String version;
    
    // Flink执行配置
    private int parallelism;
    private long checkpointInterval;
    private long checkpointTimeout;
    private long minPauseBetweenCheckpoints;
    private int maxConcurrentCheckpoints;
    private int tolerableCheckpointFailureNumber;
    private int maxRestartAttempts;
    private int restartDelaySeconds;
    
    // 监控配置
    private int monitoringInterval;
    private String logLevel;
    private boolean enableDebugSql;
    
    // 数据源配置
    private List<DataSourceConfig> dataSources;
    
    // 数据目标配置
    private List<DataSinkConfig> dataSinks;
    
    // 数据流配置
    private List<DataFlowConfig> dataFlows;
    
    // Catalog配置
    private List<CatalogConfig> catalogs;
    
    // 存储配置
    private StorageConfig storage;
    
    // 表属性配置
    private Map<String, String> tableProperties;
    
    /**
     * 数据源配置
     */
    @Data
    public static class DataSourceConfig {
        private String name;
        private String type; // kafka, mysql, postgresql, etc.
        private String connectionString;
        private String topic;
        private String bootstrapServers;
        private String groupId;
        private String username;
        private String password;
        private String database;
        private String table;
        private Map<String, String> properties;
        private List<FieldDefinition> fields; // 字段定义
    }
    
    /**
     * 数据目标配置
     */
    @Data
    public static class DataSinkConfig {
        private String name;
        private String type; // iceberg, kafka, mysql, postgresql, etc.
        private String connectionString;
        private String tableName;
        private String topic;
        private String bootstrapServers;
        private String username;
        private String password;
        private String database;
        private Map<String, String> properties;
        private List<FieldDefinition> fields; // 字段定义
    }
    
    /**
     * 数据流配置
     */
    @Data
    public static class DataFlowConfig {
        private String name;
        private String sourceTable;
        private String targetTable;
        private String transformationType; // direct, transform, aggregate, etc.
        private Map<String, String> transformationRules;
        private String filterCondition;
        private Map<String, String> properties;
        private List<FieldMapping> fieldMappings; // 字段映射配置
    }
    
    /**
     * 字段映射配置
     */
    @Data
    public static class FieldMapping {
        private String source;        // 源字段名
        private String target;        // 目标字段名
        private String transform;     // 转换表达式
        private String comment;       // 字段注释
    }
    
    /**
     * Catalog配置
     */
    @Data
    public static class CatalogConfig {
        private String name;
        private String type; // iceberg, hive, jdbc, etc.
        private String connectionString;
        private String uri;
        private String username;
        private String password;
        private String warehouse;
        private boolean isDefault = false;
        private Map<String, String> properties;
    }
    
    /**
     * 存储配置
     */
    @Data
    public static class StorageConfig {
        private String type; // minio, s3, hdfs, etc.
        private String endpoint;
        private String accessKey;
        private String secretKey;
        private String bucket;
        private String region;
        private String pathStyleAccess;
        private String sslEnabled;
        private Map<String, String> properties;
    }
    
    /**
     * 字段定义
     */
    @Data
    public static class FieldDefinition {
        private String name;           // 字段名
        private String type;           // 字段类型
        private String comment;        // 字段注释
        private boolean notNull = false;    // 是否非空
        private boolean primaryKey = false; // 是否主键
        private String defaultValue;   // 默认值
        private Map<String, String> properties; // 其他属性
    }
}
